package org.HisCanvas.ChrisRiffle.JFlightLog.swingUi.table;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import org.HisCanvas.ChrisRiffle.JFlightLog.dataModel.LogBookRec;
import org.HisCanvas.ChrisRiffle.JFlightLog.swingUi.mainTopFrame.FlightLogMainFrameController;
import org.HisCanvas.ChrisRiffle.JFlightLog.swingUi.recordDetailWindow.LogBookRecDialogController;





/**
 * Detects double-clicks on table recs to load the rec into the detail window
 * in edit mode
 * 
 * @author rif 
 */
public class FlightLogTableMouseListener extends MouseAdapter{
	
	
	
	@Override
	public void mouseClicked(MouseEvent e) {
	
		//a row may have been selected, so refresh user control component enablemenst
		// (like menu items and toolbar buttons)
		FlightLogMainFrameController.instance().configureItemsRequiringTableSelection();
		
		if( e.getClickCount() == 2 ){
			
			loadSelectedRecIntoEditDialog();		
		}
	}
	
	
	/**
	 * loadSelectedRecIntoEditDialog
	 */
	private void loadSelectedRecIntoEditDialog(){
				
		LogBookRec selectedRec = FlightLogTableController.instance().getSelectedFlight();
		
		if(selectedRec != null){
			
			LogBookRecDialogController.instance().displayEditFlightDialog(selectedRec);
		}		
	}
	
	

}


